package com.transitionseverywhere.utils;

import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOverlay;

/* loaded from: classes.dex */
public class ViewGroupOverlayUtils {
    private static final BaseViewGroupOverlayUtils IMPL;

    /* loaded from: classes.dex */
    static class BaseViewGroupOverlayUtils {
        BaseViewGroupOverlayUtils() {
        }

        public void addOverlay(ViewGroup viewGroup, View view, int i, int i2) {
            ViewOverlayPreJellybean overlay = ViewOverlayPreJellybean.getOverlay(viewGroup);
            if (overlay != null) {
                overlay.addView(view, i, i2);
            }
        }

        public void removeOverlay(ViewGroup viewGroup, View view) {
            ViewOverlayPreJellybean overlay = ViewOverlayPreJellybean.getOverlay(viewGroup);
            if (overlay != null) {
                overlay.removeView(view);
            }
        }

        public void moveViewInOverlay(ViewGroup viewGroup, View view, int i, int i2) {
            ViewOverlayPreJellybean overlay = ViewOverlayPreJellybean.getOverlay(viewGroup);
            if (overlay != null) {
                overlay.moveView(view, i, i2);
            }
        }

        public void initializeOverlay(ViewGroup viewGroup) {
            ViewOverlayPreJellybean.getOverlay(viewGroup);
        }

        public int[] getLocationOnScreenOfOverlayView(ViewGroup viewGroup, View view) {
            int[] iArr = new int[2];
            view.getLocationOnScreen(iArr);
            return iArr;
        }

        public void addCrossfadeOverlay(boolean z, View view, int i, BitmapDrawable bitmapDrawable, BitmapDrawable bitmapDrawable2) {
            if (view.getParent() == null || !(view.getParent() instanceof ViewGroup)) {
                return;
            }
            ViewOverlayPreJellybean overlay = ViewOverlayPreJellybean.getOverlay((ViewGroup) view.getParent());
            if (i == 1) {
                overlay.addDrawable(bitmapDrawable2);
            }
            overlay.addDrawable(bitmapDrawable);
        }

        public void removeCrossfadeOverlay(boolean z, View view, int i, BitmapDrawable bitmapDrawable, BitmapDrawable bitmapDrawable2) {
            if (view.getParent() == null || !(view.getParent() instanceof ViewGroup)) {
                return;
            }
            ViewOverlayPreJellybean overlay = ViewOverlayPreJellybean.getOverlay((ViewGroup) view.getParent());
            overlay.removeDrawable(bitmapDrawable);
            if (i == 1) {
                overlay.removeDrawable(bitmapDrawable2);
            }
        }
    }

    /* loaded from: classes.dex */
    static class JellyBeanMR2ViewGroupUtils extends BaseViewGroupOverlayUtils {
        @Override // com.transitionseverywhere.utils.ViewGroupOverlayUtils.BaseViewGroupOverlayUtils
        public void initializeOverlay(ViewGroup viewGroup) {
        }

        JellyBeanMR2ViewGroupUtils() {
        }

        @Override // com.transitionseverywhere.utils.ViewGroupOverlayUtils.BaseViewGroupOverlayUtils
        public void addOverlay(ViewGroup viewGroup, View view, int i, int i2) {
            moveViewInOverlay(viewGroup, view, i, i2);
            viewGroup.getOverlay().add(view);
        }

        @Override // com.transitionseverywhere.utils.ViewGroupOverlayUtils.BaseViewGroupOverlayUtils
        public void removeOverlay(ViewGroup viewGroup, View view) {
            viewGroup.getOverlay().remove(view);
        }

        @Override // com.transitionseverywhere.utils.ViewGroupOverlayUtils.BaseViewGroupOverlayUtils
        public void moveViewInOverlay(ViewGroup viewGroup, View view, int i, int i2) {
            if (i == 0 && i2 == 0) {
                return;
            }
            int[] iArr = new int[2];
            viewGroup.getLocationOnScreen(iArr);
            view.offsetLeftAndRight((i - iArr[0]) - view.getLeft());
            view.offsetTopAndBottom((i2 - iArr[1]) - view.getTop());
        }

        @Override // com.transitionseverywhere.utils.ViewGroupOverlayUtils.BaseViewGroupOverlayUtils
        public void addCrossfadeOverlay(boolean z, View view, int i, BitmapDrawable bitmapDrawable, BitmapDrawable bitmapDrawable2) {
            ViewOverlay viewOverlay = getViewOverlay(z, view);
            if (i == 1) {
                viewOverlay.add(bitmapDrawable2);
            }
            viewOverlay.add(bitmapDrawable);
        }

        @Override // com.transitionseverywhere.utils.ViewGroupOverlayUtils.BaseViewGroupOverlayUtils
        public int[] getLocationOnScreenOfOverlayView(ViewGroup viewGroup, View view) {
            viewGroup.getLocationOnScreen(r0);
            int[] iArr = {iArr[0] + view.getLeft(), iArr[1] + view.getTop()};
            return iArr;
        }

        @Override // com.transitionseverywhere.utils.ViewGroupOverlayUtils.BaseViewGroupOverlayUtils
        public void removeCrossfadeOverlay(boolean z, View view, int i, BitmapDrawable bitmapDrawable, BitmapDrawable bitmapDrawable2) {
            ViewOverlay viewOverlay = getViewOverlay(z, view);
            viewOverlay.remove(bitmapDrawable);
            if (i == 1) {
                viewOverlay.remove(bitmapDrawable2);
            }
        }

        private static ViewOverlay getViewOverlay(boolean z, View view) {
            return z ? ((ViewGroup) view.getParent()).getOverlay() : view.getOverlay();
        }
    }

    static {
        if (Build.VERSION.SDK_INT >= 18) {
            IMPL = new JellyBeanMR2ViewGroupUtils();
        } else {
            IMPL = new BaseViewGroupOverlayUtils();
        }
    }

    public static void addOverlay(ViewGroup viewGroup, View view, int i, int i2) {
        if (view != null) {
            IMPL.addOverlay(viewGroup, view, i, i2);
        }
    }

    public static void initializeOverlay(ViewGroup viewGroup) {
        IMPL.initializeOverlay(viewGroup);
    }

    public static void removeOverlay(ViewGroup viewGroup, View view) {
        if (view != null) {
            IMPL.removeOverlay(viewGroup, view);
        }
    }

    public static void moveViewInOverlay(ViewGroup viewGroup, View view, int i, int i2) {
        if (view != null) {
            IMPL.moveViewInOverlay(viewGroup, view, i, i2);
        }
    }

    public static int[] getLocationOnScreenOfOverlayView(ViewGroup viewGroup, View view) {
        return view != null ? IMPL.getLocationOnScreenOfOverlayView(viewGroup, view) : new int[2];
    }

    public static void addCrossfadeOverlay(boolean z, View view, int i, BitmapDrawable bitmapDrawable, BitmapDrawable bitmapDrawable2) {
        if (view != null) {
            IMPL.addCrossfadeOverlay(z, view, i, bitmapDrawable, bitmapDrawable2);
        }
    }

    public static void removeCrossfadeOverlay(boolean z, View view, int i, BitmapDrawable bitmapDrawable, BitmapDrawable bitmapDrawable2) {
        if (view != null) {
            IMPL.removeCrossfadeOverlay(z, view, i, bitmapDrawable, bitmapDrawable2);
        }
    }
}
